<?php
class Admin_Model_GroupUser extends Zend_Db_Table{
	protected $_name = 'group_user';
	protected $_primary = 'group_id';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	////////////
	/* select*/
	//////////
	public function selectALLUserGroup()
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/groupuser/route/selectALLUserGroup");
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];	
		return $data;
	}
	
	public function selectUserGroup($group_id)
	{// co dung		
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/groupuser/route/selectUserGroup/group_id/".$group_id);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		
		return $data;
	}
	
	////////////
	/* insert*/
	//////////
	public function insertUserGroup($data)
	{// co dung

		$data['route'] = "insertUserGroup";
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPost("/groupuser", $data);

		return $return->getBody();		
	}
	
	////////////
	/* update*/
	//////////
	public function updateUserGroup($data)
	{// co dung
		
		$data['route'] = "updateUserGroup";
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPost("/groupuser", $data);
		
		return $return->getBody();		
	}
	
	////////////
	/* delete*/
	//////////
	public function deleteUserGroup($id)
	{// co dung		
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/groupuser/route/deleteUserGroup/id/".$id);
		return $return->getBody();		
	}
	
}